Skip to content

Conversation

@pahud
Copy link
Contributor

@pahud pahud commented Aug 8, 2025

Issue # (if applicable)

Closes #35180.

Reason for this change

AWS AppConfig extensions with encrypted SQS destinations were failing silently because the SqsDestination class only granted sqs:SendMessage permissions but omitted the required KMS permissions (kms:Decrypt and kms:GenerateDataKey) needed to work with customer-managed KMS encrypted queues.

This caused a poor user experience where AppConfig extensions would appear to be configured correctly but would fail to deliver messages to encrypted SQS queues without any error indication. Users were forced to either disable encryption or manually add KMS permissions, preventing secure-by-default practices.

Description of changes

This change adds conditional KMS permission granting to the SqsDestination class in AWS AppConfig extensions:

  • Enhanced SqsDestination constructor: Modified to check for queue.encryptionMasterKey and conditionally add KMS permissions when present
  • KMS permissions added: Grants kms:Decrypt and kms:GenerateDataKey actions on the queue's encryption key when a customer-managed KMS key is detected
  • Backward compatibility maintained: Existing unencrypted queue usage continues to work unchanged with no additional permissions
  • Policy structure updated: Changed from single policy statement to array of statements to accommodate both SQS and KMS permissions

Key implementation details:

  • Follows the established pattern from S3 notifications SqsDestination which correctly handles this scenario
  • Uses conditional logic based on queue.encryptionMasterKey property to detect encrypted queues
  • Only adds KMS permissions for customer-managed keys (not AWS-managed encryption)
  • Maintains the existing policy document structure and IAM role creation pattern

Design decisions:

  • Manual KMS policy creation: Chosen over using queue.grantSendMessages() to maintain consistency with existing AppConfig patterns and provide explicit control over permissions
  • Minimal permissions: Only grants the two specific KMS actions required for SQS message operations, following principle of least privilege
  • Conditional approach: Ensures no unnecessary permissions are added for unencrypted queues

Describe any new or updated permissions being added

IAM permissions added conditionally:

  • kms:Decrypt: Required for AppConfig to decrypt messages from encrypted SQS queues
  • kms:GenerateDataKey: Required for AppConfig to encrypt messages when sending to encrypted SQS queues

These permissions are only added when:

  • The SQS queue uses customer-managed KMS encryption (queue.encryptionMasterKey is present)
  • The permissions are scoped specifically to the queue's encryption key ARN

Security impact: This change improves security by enabling encrypted SQS queues to work correctly with AppConfig extensions, promoting secure-by-default practices. The permissions follow the principle of least privilege and are only granted when necessary.

Description of how you validated changes

Unit tests (108/108 passing):

  • New encrypted queue test: Validates that KMS permissions (kms:Decrypt, kms:GenerateDataKey) are correctly added to IAM policies when using customer-managed KMS encrypted queues
  • Regression test: Confirms that unencrypted queues continue to work unchanged with only SQS permissions (no KMS permissions added)
  • Policy document validation: Verifies correct CloudFormation template generation with proper IAM policy structure
  • Cross-module testing: Full test suite (15,774/15,783 tests passing) confirms no regressions in other CDK modules

Integration tests (1/1 passing):

  • CloudFormation deployment: Existing integration test validates that AppConfig extensions with SQS destinations deploy successfully to AWS
  • Template generation: Verified that CloudFormation templates include correct IAM policies for both encrypted and unencrypted scenarios
  • Real AWS validation: Integration tests confirm templates deploy successfully and resources are created correctly

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Fixes silent failures when AppConfig extensions use encrypted SQS queues by conditionally granting kms:Decrypt and kms:GenerateDataKey permissions when queue.encryptionMasterKey is present.

Closes aws#35180
@aws-cdk-automation aws-cdk-automation requested a review from a team August 8, 2025 18:02
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p2 labels Aug 8, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Aug 8, 2025
@pahud pahud marked this pull request as ready for review August 8, 2025 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/medium Medium work item – several days of effort p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(aws-appconfig): Policy from SqsDestination does not grant access to queue's encryption key

2 participants